<template>
	<view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				code:""
			}
		},
		onLoad(e) {

		},
		onShow() {
			this.getCode()
		},
		methods: {
			getUrlCode() {
			var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
			    //保存数据的对象
			    args = {},
			    //取得每一项
			    items = qs.length ? qs.split("&") : [],
			    item = null,
			    name = null,
			    value = null,
			    //在for 循环中使用
			    i = 0,
			    len = items.length;
			    //逐个将每一项添加到args 对象中
			    for (i=0; i < len; i++){
			        item = items[i].split("=");
			        name = decodeURIComponent(item[0]);
			        value = decodeURIComponent(item[1]);
			        if (name.length) {
			            args[name] = value;
			        }
			    }
			    return args;
			},
			 getCode() {
				// 非静默授权，第一次有弹框
				var local = window.location.href; // 获取页面url
				var appid = 'wx882ef50fd0e0cbc3';
				let id = 1
				var url= "https://zhibo.renruikeji.cn/gongzhonghao/";
				// var url= "https://mes.renruikeji.cn/gongzhonghao/";
				var code =this.getUrlCode();
				if (!code.code) {
					// 如果没有code，则去请求
					window.location.assign ('https://open.weixin.qq.com/connect/oauth2/authorize?appid=' +
              appid +
              '&redirect_uri=' +
              url +
              '&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect');
				} else {
          if(uni.getStorageSync('toVideo')){
            window.location.href=uni.getStorageSync("gzh_url")+'&g_z_code='+code.code;
          }else {
            window.location.href=url+'#'+uni.getStorageSync("gzh_url")+'?g_z_code='+code.code
            // uni.navigateTo({
            //   url:uni.getStorageSync("gzh_url")+'?g_z_code='+code.code
            // })
          }
				}
			}
		}
	}
</script>

<style>

</style>
